# 导入requests
import requests
import random
phone = random.randint(13000000000,13999999999)
# print(f'生成随机的手机号{phone}')
testcase={
    "header":{
        "token":None
    },
       "register":{
          "url":"http://101.35.128.30:28019/api/v1/user/register",
           "body":{
               "loginName": phone,
                 "password": "123456"
            }
},
       "login":{
           "url":"http://101.35.128.30:28019/api/v1/user/login",
           "body":{
                  "loginName": phone,
                 "passwordMd5": "E10ADC3949BA59ABBE56E057F20F883E"
            }
       },
    "search":{
        "url":"http://101.35.128.30:28019/api/v1/search",
        "query":{
           "keyword": "iphone"
}
    }
}

r1 = requests.post(url=testcase["register"]["url"],json=testcase["register"]["body"])
print(r1.status_code,r1.json())
r2=requests.post(url=testcase["login"]["url"],json=testcase["login"]["body"])
print(r2.status_code,r2.json())

testcase["header"]["token"]=r2.json()["data"]

print(testcase["header"])
r3 = requests.get(url=testcase["search"]["url"],params=testcase["search"]["query"],headers=testcase["header"])
print(r3.status_code,r3.json())